package com.afkt.app.utils;

import ohos.aafwk.ability.SystemMemoryInfo;
import ohos.agp.window.service.Display;
import ohos.agp.window.service.DisplayManager;
import ohos.app.Context;
import ohos.app.IAbilityManager;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Optional;

public class GetInfoUtils {

    /**
     * 获取手机总内存
     * */
    public static String getPhoneMemory(IAbilityManager abilityManager){
        SystemMemoryInfo systemMemoryInfo = new SystemMemoryInfo();
        IAbilityManager iAbilityManager = abilityManager;
        iAbilityManager.getSystemMemoryInfo(systemMemoryInfo);
        Long totalSysMem = (Long)systemMemoryInfo.getTotalSysMem();
        // double GB =  totalSysMem/(1024*1024*1024);
        BigDecimal bigDecimal = new BigDecimal(totalSysMem);
        BigDecimal mem = bigDecimal.divide(new BigDecimal(1024)).divide(new BigDecimal(1024)).divide(new BigDecimal(1024));
        BigDecimal bigDecimal1 = mem.setScale(2, RoundingMode.HALF_UP);

        return bigDecimal1+"G";
    }


    /**
     * 获取手机可用内存
     * */
    public static String getPhoneAvailMemory(IAbilityManager abilityManager){
        SystemMemoryInfo systemMemoryInfo = new SystemMemoryInfo();
        IAbilityManager iAbilityManager = abilityManager;
        iAbilityManager.getSystemMemoryInfo(systemMemoryInfo);
        Long totalSysMem = (Long)systemMemoryInfo.getAvailSysMem();
        // double GB =  totalSysMem/(1024*1024*1024);
        BigDecimal bigDecimal = new BigDecimal(totalSysMem);
        BigDecimal mem = bigDecimal.divide(new BigDecimal(1024)).divide(new BigDecimal(1024)).divide(new BigDecimal(1024));
        BigDecimal bigDecimal1 = mem.setScale(2, RoundingMode.HALF_UP);
        return bigDecimal1+"G";
    }




    /**
     * 获取屏幕宽度方法
     *
     * @return 屏幕宽度
     */
    public static int getDisplayWidthInPx( Context context) {
        Display display = DisplayManager.getInstance().getDefaultDisplay(context).get();
        return display.getAttributes().width;
    }
    /**
     * 获取屏幕DPI密度
     * */
    public static int getDensityDpi( Context context) {
        Display display = DisplayManager.getInstance().getDefaultDisplay(context).get();
        return display.getAttributes().densityDpi;
    }

    /**
     * 获取屏幕高度
     * */
    public static int getheight( Context context) {
        Optional<Display> display = DisplayManager.getInstance().getDefaultDisplay(context);
        return display.get().getRealAttributes().height;
    }


    /**
     * 获取像素密度 (密度)
     * */
    public static int getDensityPixels( Context context) {
        Display display = DisplayManager.getInstance().getDefaultDisplay(context).get();
        return (int) display.getAttributes().densityPixels;
    }

    /**
     * 屏幕缩放密度
     * */
    public static int getScalDensity( Context context) {
        Display display = DisplayManager.getInstance().getDefaultDisplay(context).get();
        return (int) display.getAttributes().scalDensity;
    }

    /**
     * 屏幕X轴DPI
     * */
    public static int getScreenXDpi( Context context) {
        Display display = DisplayManager.getInstance().getDefaultDisplay(context).get();
        return (int) display.getAttributes().xDpi;
    }


    /**
     * 屏幕Y轴DPI
     * */
    public static int getScreenYDpi( Context context) {
        Display display = DisplayManager.getInstance().getDefaultDisplay(context).get();
        return (int) display.getAttributes().yDpi;
    }


}
